import { VmErr } from "../svm/VmErr";
import { BaseNode } from "./com/BaseNode";

export class FunctionNode extends BaseNode {

    constructor(name?: string) {
        super(name ? name : 'Function');
        this.edit.out = true
        this.type = 'Function'
        this.outputName = 'line'
        this.edit.delete = false
        this.canReference = true
        this.bgColor = '#009688'
        this.addAttribute({
            name: "argsNumber",
            value: '1',
            type: 'number',
        })
        this.addInput({ key: 'line' })
        this.refresh()
    }

    verify(): boolean {
        const argsNumber = this.getAttribute('argsNumber')
        if(argsNumber&&/^[0-9]+$/.test(argsNumber.value)){
            return true
        }
        throw new VmErr(this.id, `${this.titleContent} args wrong`)
    }
}